package com.xcc.singletonpattern.demo02;

/**
 * @Description: ChocolateBoiler
 * @Author xiechuang
 * @Date 2022/9/6
 */
public class ChocolateBoiler {

    private static ChocolateBoiler uniqueInstance;

    private boolean empty;
    private boolean boiled;

    public static ChocolateBoiler getInstance() {
        if (uniqueInstance == null) {
            uniqueInstance = new ChocolateBoiler();
        }
        return uniqueInstance;
    }

    private ChocolateBoiler() {
        empty = true;
        boiled = false;
    }

    public void fill() {
        if (empty) {
            empty = false;
            boiled = true;
        }
    }

    public void drain() {
        if (!isEmpty() && isBoiled()) {
            empty = true;
        }
    }

    public void boil() {
        if (!isEmpty() && !isBoiled()) {
            boiled = true;
        }
    }

    private boolean isBoiled() {
        return boiled;
    }

    private boolean isEmpty() {
        return empty;
    }


}
